package edu.notebook.service.impl;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import edu.notebook.dao.UserDao;
import edu.notebook.domain.User;
import edu.notebook.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl extends ServiceImpl<UserDao, User> implements UserService {
    public UserServiceImpl() {
        super();
    }
    @Autowired
    private UserDao userDao;

    @Override
    public Boolean saveUser(User user) {
        return userDao.insert(user) > 0;
    }

    @Override
    public Boolean update(User user) {
        return userDao.updateById(user) > 0;
    }

    @Override
    public Boolean delete(Integer id) {
        return userDao.deleteById(id) > 0;
    }

    @Override
    public User getById(Integer id) {
        return userDao.selectById(id);
    }

    @Override
    public IPage<User> getPage(int currentPage, int pageSize) {
        IPage page = new Page(currentPage,pageSize);
        userDao.selectPage(page,null);
        return page;
    }

    //用户登录
    @Override
    public User login(String username, String password) {
        return userDao.login(username,password);
    }

    //修改密码
    @Override
    public Boolean updatePassword(String id, String password) {
        return userDao.updatePassword(id,password) > 0;
    }

    @Override
    public List<User> getAll() {
        return userDao.selectList(null);
    }


}
